import dask.dataframe as dd
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression

# 读取csv文件
df = dd.read_csv("filtered_data.csv",assume_missing=True)

# 选择需要的数据段和环境数据段
skj_cols = ["skj_c_una", "skj_c_log", "skj_c_dfad", "skj_c_afad"]
env_cols = ["Temp_0", "Temp_50", "Temp_100", "Temp_150", "Temp_200", "Temp_250", "Temp_300", "SSH", "MLT"]
df = df[skj_cols + env_cols]



# 将数据转换为pandas DataFrame，并填充NaN值为0
df = df.compute()
df.fillna(0, inplace=True)
target_list = ["skj_c_una", "skj_c_log", "skj_c_dfad", "skj_c_afad"]

for target in target_list:
    '''
    # 合并SKJ围网产量数据段
    #df["SKJ"] = df[skj_cols].sum(axis=1)
    df["SKJ"] = df[target]


    # 可视化SKJ围网产量数据段和环境数据段之间的关系
    sns.pairplot(df, x_vars=env_cols, y_vars=["SKJ"], height=5)
    plt.savefig(f'test{target}.png')
    '''
    # 探究不同作业方式对环境数据段的影响
    for col in env_cols:
        X = df[["skj_c_una", "skj_c_log", "skj_c_dfad", "skj_c_afad"]]
        y = df[col]
        # 删除包含NaN值的行
        df_temp = pd.concat([X, y], axis=1)
        df_temp.dropna(inplace=True)
        #X = df_temp[["skj_c_una", "skj_c_log", "skj_c_dfad", "skj_c_afad"]]
        X = df_temp[["skj_c_una"]]
        y = df_temp[col]
        model = LinearRegression()
        model.fit(X, y)
        print(target, col)
        print("Coefficients:", model.coef_)
        print("Intercept:", model.intercept_)
        print("R-squared:", model.score(X, y))
        print()

